<?php
session_start ();
header ( "Content-type: image/PNG" );

srand ( ( double ) microtime () * 1000000 );
$im = imagecreate ( 62, 20 );
$black = ImageColorAllocate ( $im, 0, 0, 0 );
$white = ImageColorAllocate ( $im, 255, 255, 255 );
$gray = ImageColorAllocate ( $im, 200, 200, 200 );
imagefill ( $im, 68, 30, $gray );
while ( ($authnum = rand () % 100000) < 10000 );
	
//将四位整数验证码绘入图片
imagestring ( $im, 5, 10, 3, $authnum, $white );
 //加入干扰象素
for($i = 0; $i < 400; $i ++){
	$randcolor = ImageColorallocate ( $im, rand ( 150, 255 ), rand ( 150, 255 ), rand (150, 255 ) );
	imagesetpixel ( $im, rand () % 70, rand () % 30, $randcolor );
}
ImagePNG ( $im );
ImageDestroy ( $im );
$_SESSION ['SESSION_VALIDATE_CODE'] = $authnum . '';
?> 
